import service from './index';
import {
  User,
  ITch,
  IPageParams,
  IModifyPwd,
  IFalseDelete,
  ITchStageParams,
  IStu,
  IStuWorkChartParams,
  IStuWorkPageParams,
  IExamScoreChartParams,
  IStuScoreChartParams,
  IHomePageChartParams,
  IRecruitmentParams,
  ICourseTable,
  IEditCourse,
  ITchPageParams,
  IRecruitment,
} from '../type';
import { useUserStore } from '../store/user';
import { baseURL } from './index';
const store = useUserStore();

export const useAPI = () => {
  return {
    baseUrl: baseURL,
    //登录
    login: (data: User) => {
      return service({
        url: '/login',
        method: 'post',
        data,
      });
    },
    //token换个人信息
    getInfoByToken: (token: string) => {
      return service({
        url: '/getInfoByToken',
        method: 'post',
        data: token,
      });
    },
    //修改密码
    modifyPwd: (data: ITch | IModifyPwd, role: string) => {
      return service({
        url: `/${role}/modifyPwd`,
        method: 'post',
        data,
      });
    },
    //根据工号，学号查询信息
    forgetPwd: (params: any, role: string) => {
      return service({
        url: `/${role}/forgetPassword`,
        method: 'get',
        params,
      });
    },
    //修改个人信息
    save: (data: IStu | ITch | ICourseTable[] | IEditCourse | IRecruitment, role: string, address: string) => {
      // /teacher/findAll/stuInfo
      // /teacher/findPage/stuScore
      return service({
        url: `/${role}/save/${address}`,
        method: 'post',
        data,
      });
    },
    //分页查询
    findPage: (data: IPageParams | IStuWorkPageParams | IRecruitmentParams | ITchPageParams, role: string, address: string) => {
      // /teacher/findAll/stuInfo
      // /teacher/findPage/stuScore
      return service({
        url: `/${role}/findPage/${address}`,
        method: 'post',
        data,
      });
    },
    //查询全部Get
    findAllByGet: (params: ITchStageParams | IStuWorkChartParams | undefined, role: string, address: string) => {
      // /teacher/findAll/tchStage
      return service({
        url: `/${role}/findAll/${address}`,
        method: 'get',
        params,
      });
    },
    //查询全部Get
    findAllByPost: (data: any, role: string, address: string) => {
      // /teacher/findAll/tchStage
      return service({
        url: `/${role}/findAll/${address}`,
        method: 'post',
        data,
      });
    },
    //假删除
    falseDelete: (data: Array<string>, role: string, address: string) => {
      return service({
        url: `/${role}/falseDeleteByIds/${address}`,
        method: 'delete',
        data,
      });
    },
    //永久删除
    trueDelete: (data: Array<string>, role: string, address: string) => {
      return service({
        url: `/${role}/trueDeleteByIds/${address}`,
        method: 'delete',
        data,
      });
    },
    //获取图表数据
    getChartData: (
      params: IStuWorkChartParams | IExamScoreChartParams | IStuScoreChartParams | IHomePageChartParams | undefined,
      role: string,
      address: string
    ) => {
      //stuWork,examScore,stuScore
      return service({
        url: `/${role}/chartData/${address}`,
        method: 'get',
        params,
      });
    },
    //post方式表格导出
    fileExport: (data: any, address: string) => {
      return service({
        url: `/teacher/fileExport/${address}`,
        method: 'post',
        data,
      });
    },
  };
};
